package com.shunde.xunjian.util;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Results {

    public static final Object INCORRECT_PARAMETERS = Results.error("参数有误");
    public static final Object AUTHORIZATION_EXCEPTION = Results.error("请求权限不足");

    Map<String, Object> objectMap = null;

    private Results() {
        objectMap = new HashMap<>();
    }

    public static Object success(Object body) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "");
        map.put("body", body);
        return map;
    }

    public static Object ss(Object body) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "请求成功");
        map.put("body", body);
        return map;
    }

    public static Object error(String message) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", -1);
        map.put("msg", message);
        return map;
    }

    public Results put(String key, Object value) {
        objectMap.put(key, value);
        return this;
    }

    public Results putAll(Map<String, Object> map){
        objectMap.putAll(map);
        return this;
    }

    public Map<String, Object> toMap() {
        return objectMap;
    }

    public static Results of() {
        return new Results();
    }

}
